{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2b565aca-723d-4e33-9d8a-3346f5ee5825",
   "metadata": {},
   "source": [
    "# 1.pandas入门\n",
    "## 1.1、pands的Series\n",
    "### 1.1.1、pands一维数组的创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8e125214-212e-43e1-8186-cfca0a37e8be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    1.0\n",
      "1    2.0\n",
      "2    3.0\n",
      "3    4.0\n",
      "4    5.0\n",
      "5    6.0\n",
      "6    NaN\n",
      "dtype: float64\n",
      "3.0\n",
      "a    1.0\n",
      "b    2.0\n",
      "c    3.0\n",
      "d    4.0\n",
      "e    5.0\n",
      "f    6.0\n",
      "g    NaN\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "lst = [1,2,3,4,5,6,None]\n",
    "S = pd.Series(lst)\n",
    "print(S)\n",
    "print(S[2])\n",
    "#创建一行\n",
    "S1 = pd.Series(lst,index=list('abcdefg'),dtype=float)\n",
    "print(S1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bec391c-c3b2-4ff6-bb3d-d1f1da6171e8",
   "metadata": {},
   "source": [
    "Series主要对应着一行，虽然可以用它来创建多行数据，但是操作起来不是很方便"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "90fd5800-fe27-4083-8d8c-c2f745476437",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0       [1, 2, 3, 4]\n",
      "1       [5, 6, 7, 8]\n",
      "2    [9, 10, 11, 12]\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "arr = np.array([\n",
    "    [1,2,3,4],\n",
    "    [5,6,7,8],\n",
    "    [9,10,11,12]\n",
    "])\n",
    "#会报错，Series表示的是一行\n",
    "#S = pd.Series(arr)\n",
    "#此时其实是每一行当做一个值\n",
    "S = pd.Series(list(arr))\n",
    "print(S)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "447907f3-5430-43b0-9f3c-8e6e1f3aba67",
   "metadata": {},
   "source": [
    "Pandas的底层逻辑其实是Numpy实现的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "edf83858-8b34-4568-8285-6a580c656f4f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6 7] <class 'numpy.ndarray'>\n",
      "0     1\n",
      "1     2\n",
      "2    10\n",
      "3     4\n",
      "4     5\n",
      "5     6\n",
      "6     7\n",
      "dtype: int64\n",
      "[ 1  2 10  4  5  6  7]\n",
      "[99  2 10  4  5  6  7] [99  2 10  4  5  6  7]\n",
      "0    99\n",
      "1     2\n",
      "2    10\n",
      "3     4\n",
      "4     5\n",
      "5     6\n",
      "6     7\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "arr = np.array([1,2,3,4,5,6,7])\n",
    "s = pd.Series(arr)\n",
    "print(s.values,type(s.values))\n",
    "arr[2] = 10\n",
    "#修改了np，也会同时修改pandas\n",
    "print(s)\n",
    "#讲Series转换为numpy\n",
    "arr2 = s.to_numpy()\n",
    "#需要注意arr2就是原来numpy的指针，是一个对象\n",
    "print(arr2)\n",
    "arr2[0] = 99\n",
    "print(arr2,arr)\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9acbb88-58c0-45db-af21-db617f5520dd",
   "metadata": {},
   "source": [
    "### 1.1.2、Pandas的iloc和loc\n",
    "`iloc` 是 Pandas 里“**按位置**取数”的专用索引器（**i**nteger **loc**ation）。 `df.iloc[...]` 里的**中括号**，其实是 Python 的“**下标运算**”（`__getitem__`），并不是函数调用。换句话说：`df.iloc[行选择, 列选择]` 等价于 `df.iloc.__getitem__((行选择, 列选择))`。\\\n",
    "如果用小括号就是函数调用了（`df.iloc(...)`），那是不存在的接口。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fd068ab8-5e3a-47db-b715-505d54cecda7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "B    2\n",
      "D    4\n",
      "dtype: int64\n",
      "1\n",
      "A    1\n",
      "B    2\n",
      "C    3\n",
      "D    4\n",
      "dtype: int64\n",
      "E    5\n",
      "D    4\n",
      "C    3\n",
      "B    2\n",
      "A    1\n",
      "dtype: int64\n",
      "****************************************************************************************************\n",
      "E    5\n",
      "D    4\n",
      "C    3\n",
      "B    2\n",
      "A    1\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "arr = np.array([1,2,3,4,5])\n",
    "S = pd.Series(arr,index=list('ABCDE'))\n",
    "#获取第一个元素\n",
    "print(S.iloc[0])\n",
    "#也可以进行切片操作\n",
    "print(S.iloc[1::2])\n",
    "#使用loc可以通过索引来访问\n",
    "print(S.loc['A'])\n",
    "#loc是包头包尾\n",
    "print(S.loc['A':'D'])\n",
    "print(S.loc['E'::-1])\n",
    "print('*'*100)\n",
    "print(S['E'::-1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f49aa9e3-e085-4073-b645-4d0e1bc5792e",
   "metadata": {},
   "source": [
    "### 1.1.3、Series的其他操作\n",
    "- 常用属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ed70454f-3e65-4fb4-9873-14fc91312457",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['A', 'B', 'C', 'D', 'E'], dtype='object')\n",
      "[80. 85. 90. nan 70.]\n",
      "float64\n",
      "(5,)\n",
      "None\n",
      "80.0\n",
      "80.0\n",
      "B    85.0\n",
      "C    90.0\n",
      "dtype: float64\n",
      "B    85.0\n",
      "C    90.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "s = pd.Series([80, 85, 90, np.nan, 70], index=['A','B','C','D','E'])\n",
    "\n",
    "print(s.index)      # 索引\n",
    "print(s.values)     # 值（NumPy 数组）\n",
    "print(s.dtype)      # 数据类型\n",
    "print(s.shape)      # 长度\n",
    "print(s.name)       # 名称\n",
    "\n",
    "print(s['A'])\n",
    "#不能使用s[0]来访问\n",
    "# print(s[0])\n",
    "print(s.iloc[0])\n",
    "#可以使用索引\n",
    "print(s[s>80])\n",
    "print(s[(s>80)&(s<=90)])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58511a4a-7e51-440e-9d26-713f218b71a2",
   "metadata": {},
   "source": [
    "- 其他操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d1088b6b-64df-4c12-ace2-03af7aa19b12",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A     80.0\n",
      "B    105.0\n",
      "C    110.0\n",
      "D      NaN\n",
      "E     70.0\n",
      "dtype: float64\n",
      "91.25 110.0 70.0 <bound method Series.std of A     80.0\n",
      "B    105.0\n",
      "C    110.0\n",
      "D      NaN\n",
      "E     70.0\n",
      "dtype: float64>\n",
      "count      4.00000\n",
      "mean      91.25000\n",
      "std       19.31105\n",
      "min       70.00000\n",
      "25%       77.50000\n",
      "50%       92.50000\n",
      "75%      106.25000\n",
      "max      110.00000\n",
      "dtype: float64\n",
      "A    False\n",
      "B    False\n",
      "C    False\n",
      "D     True\n",
      "E    False\n",
      "dtype: bool\n",
      "A     80.00\n",
      "B    105.00\n",
      "C    110.00\n",
      "D     91.25\n",
      "E     70.00\n",
      "dtype: float64\n",
      "A     80.0\n",
      "B    105.0\n",
      "C    110.0\n",
      "E     70.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "s = pd.Series([80, 85, 90, np.nan, 70], index=['A','B','C','D','E'])\n",
    "#同样支持广播操作\n",
    "s[s>80]+=20\n",
    "print(s)\n",
    "#也有具体的方法\n",
    "print(s.mean(),s.max(),s.min(),s.std)\n",
    "#统计所有的数据\n",
    "print(s.describe())\n",
    "print(s.isna())              # 判断缺失\n",
    "print(s.fillna(s.mean()))    # 用均值填充缺失值\n",
    "print(s.dropna())            # 删除缺失值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ecf7dbd-dbf3-49fe-b961-0127f8c1c501",
   "metadata": {},
   "source": [
    "## 1.2、pandas二维数组的应用\n",
    "### 1.2.1、创建Dataframe\n",
    "Pandas使用的DataFrame来操作二维数组，此时需要行和列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4ab5c45e-202d-4a32-a621-c5a010632124",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>47</td>\n",
       "      <td>57</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>82</td>\n",
       "      <td>86</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>70</td>\n",
       "      <td>84</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>96</td>\n",
       "      <td>92</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>91</td>\n",
       "      <td>88</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>67</td>\n",
       "      <td>66</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>36</td>\n",
       "      <td>31</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>99</td>\n",
       "      <td>58</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>70</td>\n",
       "      <td>31</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>74</td>\n",
       "      <td>51</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语\n",
       "A  47  57  60\n",
       "B  82  86  76\n",
       "C  70  84  68\n",
       "D  96  92  61\n",
       "E  91  88  34\n",
       "F  67  66  48\n",
       "G  36  31  74\n",
       "H  99  58  50\n",
       "I  70  31  42\n",
       "J  74  51  81"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "****************************************************************************************************\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>47</td>\n",
       "      <td>57</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>82</td>\n",
       "      <td>86</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70</td>\n",
       "      <td>84</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>96</td>\n",
       "      <td>92</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>91</td>\n",
       "      <td>88</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>67</td>\n",
       "      <td>66</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>36</td>\n",
       "      <td>31</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>99</td>\n",
       "      <td>58</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70</td>\n",
       "      <td>31</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>74</td>\n",
       "      <td>51</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语\n",
       "0  47  57  60\n",
       "1  82  86  76\n",
       "2  70  84  68\n",
       "3  96  92  61\n",
       "4  91  88  34\n",
       "5  67  66  48\n",
       "6  36  31  74\n",
       "7  99  58  50\n",
       "8  70  31  42\n",
       "9  74  51  81"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "#十人三科的数据\n",
    "arr = np.random.randint(30,100,(10,3))\n",
    "df = pd.DataFrame(arr)\n",
    "# print(df)\n",
    "# display(df)\n",
    "#可以设置行和列的信息\n",
    "df.index = list('ABCDEFGHIJ') \n",
    "df.columns = ['语文','数学','英语']\n",
    "display(df)\n",
    "#也可以在创建的时候设置\n",
    "df = pd.DataFrame(arr,columns=['语文','数学','英语'])\n",
    "print('*'*100)\n",
    "display(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79c21009-46f7-4f2e-9a99-98273ebd262e",
   "metadata": {},
   "source": [
    "- 基于字典的方式创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "6b1b92b8-8145-4a02-91ac-0e8f3a89fffd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>张三</td>\n",
       "      <td>80</td>\n",
       "      <td>70</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>李四</td>\n",
       "      <td>90</td>\n",
       "      <td>50</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>王五</td>\n",
       "      <td>60</td>\n",
       "      <td>80</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>赵六</td>\n",
       "      <td>50</td>\n",
       "      <td>55</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   姓名  语文  数学  英语\n",
       "0  张三  80  70  90\n",
       "1  李四  90  50  40\n",
       "2  王五  60  80  20\n",
       "3  赵六  50  55  40"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>物理</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>张三</td>\n",
       "      <td>44</td>\n",
       "      <td>80</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>李四</td>\n",
       "      <td>78</td>\n",
       "      <td>67</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>王五</td>\n",
       "      <td>56</td>\n",
       "      <td>78</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>赵六</td>\n",
       "      <td>88</td>\n",
       "      <td>56</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>朱琦</td>\n",
       "      <td>56</td>\n",
       "      <td>92</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name  语文  数学  物理\n",
       "0   张三  44  80  79\n",
       "1   李四  78  67  60\n",
       "2   王五  56  78  70\n",
       "3   赵六  88  56  42\n",
       "4   朱琦  56  92  56"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "achs = {\n",
    "    '姓名':['张三','李四','王五','赵六'],\n",
    "    '语文':[80,90,60,50],\n",
    "    '数学':[70,50,80,55],\n",
    "    '英语':[90,40,20,40]\n",
    "}\n",
    "df = pd.DataFrame(achs)\n",
    "display(df)\n",
    "achs1 = [\n",
    "    {'name':'张三','语文':44,'数学':80,'物理':79},\n",
    "    {'name':'李四','语文':78,'数学':67,'物理':60},\n",
    "    {'name':'王五','语文':56,'数学':78,'物理':70},\n",
    "    {'name':'赵六','语文':88,'数学':56,'物理':42},\n",
    "    {'name':'朱琦','语文':56,'数学':92,'物理':56},\n",
    "]\n",
    "df = pd.DataFrame(achs1)\n",
    "display(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c07fc8cd-e552-4ef7-86fa-d6f56c4941cc",
   "metadata": {},
   "source": [
    "### 1.2.2、DataFrame的基本属性\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "39d61844-b7f2-4b4c-ad0e-f596feae4472",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10, 3)\n",
      "RangeIndex(start=0, stop=10, step=1)\n",
      "RangeIndex(start=0, stop=3, step=1)\n",
      "[[74 94 65]\n",
      " [97 48 64]\n",
      " [60 78 31]\n",
      " [65 48 73]\n",
      " [49 64 75]\n",
      " [78 99 45]\n",
      " [57 85 47]\n",
      " [70 70 71]\n",
      " [50 43 72]\n",
      " [50 67 83]]\n",
      "0    int32\n",
      "1    int32\n",
      "2    int32\n",
      "dtype: object\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 10 entries, 0 to 9\n",
      "Data columns (total 3 columns):\n",
      " #   Column  Non-Null Count  Dtype\n",
      "---  ------  --------------  -----\n",
      " 0   0       10 non-null     int32\n",
      " 1   1       10 non-null     int32\n",
      " 2   2       10 non-null     int32\n",
      "dtypes: int32(3)\n",
      "memory usage: 252.0 bytes\n",
      "None\n",
      "               0          1         2\n",
      "count  10.000000  10.000000  10.00000\n",
      "mean   65.000000  69.600000  62.60000\n",
      "std    15.253415  19.568682  16.31768\n",
      "min    49.000000  43.000000  31.00000\n",
      "25%    51.750000  52.000000  51.25000\n",
      "50%    62.500000  68.500000  68.00000\n",
      "75%    73.000000  83.250000  72.75000\n",
      "max    97.000000  99.000000  83.00000\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "#十人三科的数据\n",
    "arr = np.random.randint(30,100,(10,3))\n",
    "df = pd.DataFrame(arr)\n",
    "print(df.shape)        # (行数, 列数)\n",
    "print(df.index)        # 行标签\n",
    "print(df.columns)      # 列名\n",
    "print(df.values)       # 二维NumPy数组\n",
    "print(df.dtypes)       # 每列的数据类型\n",
    "print(df.info())       # 结构信息\n",
    "print(df.describe())   # 数值统计摘要\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e18e63c-d184-48f5-9e49-e73c52959645",
   "metadata": {},
   "source": [
    "### 1.2.3、取值与访问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "20d2d1ac-9c0f-4e95-bb84-6a62e4245e6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>54</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语\n",
       "A  38  54  97\n",
       "B  78  40  82\n",
       "C  83  96  44\n",
       "D  64  54  45\n",
       "E  90  88  46\n",
       "F  39  32  57\n",
       "G  34  61  31\n",
       "H  43  34  89\n",
       "I  97  37  79\n",
       "J  77  95  91"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A    38\n",
      "B    78\n",
      "C    83\n",
      "D    64\n",
      "E    90\n",
      "F    39\n",
      "G    34\n",
      "H    43\n",
      "I    97\n",
      "J    77\n",
      "Name: 语文, dtype: int32\n",
      "A    54\n",
      "B    40\n",
      "C    96\n",
      "D    54\n",
      "E    88\n",
      "F    32\n",
      "G    61\n",
      "H    34\n",
      "I    37\n",
      "J    95\n",
      "Name: 数学, dtype: int32\n",
      "语文    38\n",
      "数学    54\n",
      "英语    97\n",
      "Name: A, dtype: int32\n",
      "A    97\n",
      "B    82\n",
      "C    44\n",
      "D    45\n",
      "E    46\n",
      "F    57\n",
      "G    31\n",
      "H    89\n",
      "I    79\n",
      "J    91\n",
      "Name: 英语, dtype: int32\n",
      "97\n",
      "97\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "np.random.seed(100)\n",
    "#十人三科的数据\n",
    "arr = np.random.randint(30,100,(10,3))\n",
    "df = pd.DataFrame(arr,index=list('ABCDEFGHIJ'),columns=['语文','数学','英语'])\n",
    "display(df)\n",
    "print(df['语文'])#显示语文成绩\n",
    "print(df.loc[:,'数学'])#通过loc来获取数学成绩\n",
    "print(df.iloc[0])#通过下标来获取\n",
    "print(df.iloc[:,2])#通过下标来获取行\n",
    "#获取某个学生信息\n",
    "print(df.loc['A','英语'])#找A学生的英语\n",
    "print(df.iloc[0,2])#通过下标取A学生的英语"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6005f01f-4182-4759-b972-a1fc534dc75c",
   "metadata": {},
   "source": [
    "#### iloc的使用\n",
    "df.iloc[行选择, 列选择] 等价于 df.iloc.__getitem__((行选择, 列选择))\n",
    "| 选择器类型   | 示例                                | 结果                          |\n",
    "| ------- | --------------------------------- | --------------------------- |\n",
    "| 单个整数    | `df.iloc[2, 1]`                   | 标量（第3行第2列）                  |\n",
    "| 切片      | `df.iloc[1:4, 0:2]`               | DataFrame，**左闭右开**（不含4、不含2） |\n",
    "| 整数列表/数组 | `df.iloc[[0, 3, 3], [2, 0]]`      | 可重排、可重复选择                   |\n",
    "| 布尔列表/数组 | `df.iloc[[True, False, True], :]` | 按位置布尔筛选（长度必须与轴长度一致）         |\n",
    "| 全部（冒号）  | `df.iloc[:, 1]`                   | 一列（Series）                  |\n",
    "| 负索引     | `df.iloc[-1, -2]`                 | 倒数第1行、第2列                   |\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "f446173c-63bb-476b-b53d-41a7ac5d8108",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>物理</th>\n",
       "      <th>Python</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>张三</th>\n",
       "      <td>100</td>\n",
       "      <td>40</td>\n",
       "      <td>80</td>\n",
       "      <td>42</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>李四</th>\n",
       "      <td>80</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "      <td>52</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王五</th>\n",
       "      <td>90</td>\n",
       "      <td>60</td>\n",
       "      <td>50</td>\n",
       "      <td>63</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     语文  数学  英语  物理  Python\n",
       "张三  100  40  80  42      75\n",
       "李四   80  90  90  52      43\n",
       "王五   90  60  50  63      65"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "80\n",
      "语文        90\n",
      "数学        60\n",
      "英语        50\n",
      "物理        63\n",
      "Python    65\n",
      "Name: 王五, dtype: int64 (5,)\n",
      "****************************************************************************************************\n",
      "张三    80\n",
      "李四    90\n",
      "王五    50\n",
      "Name: 英语, dtype: int64 (3,)\n",
      "    英语\n",
      "张三  80\n",
      "李四  90\n",
      "王五  50 (3, 1)\n",
      "****************************************************************************************************\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>英语</th>\n",
       "      <th>语文</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>张三</th>\n",
       "      <td>80</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王五</th>\n",
       "      <td>50</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王五</th>\n",
       "      <td>50</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    英语   语文\n",
       "张三  80  100\n",
       "王五  50   90\n",
       "王五  50   90"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>物理</th>\n",
       "      <th>Python</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>张三</th>\n",
       "      <td>100</td>\n",
       "      <td>40</td>\n",
       "      <td>80</td>\n",
       "      <td>42</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王五</th>\n",
       "      <td>90</td>\n",
       "      <td>60</td>\n",
       "      <td>50</td>\n",
       "      <td>63</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     语文  数学  英语  物理  Python\n",
       "张三  100  40  80  42      75\n",
       "王五   90  60  50  63      65"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "张三     True\n",
      "李四    False\n",
      "王五     True\n",
      "Name: 语文, dtype: bool\n",
      "张三     True\n",
      "李四    False\n",
      "王五     True\n",
      "Name: 语文, dtype: bool\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>物理</th>\n",
       "      <th>Python</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>张三</th>\n",
       "      <td>100</td>\n",
       "      <td>40</td>\n",
       "      <td>80</td>\n",
       "      <td>42</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王五</th>\n",
       "      <td>90</td>\n",
       "      <td>60</td>\n",
       "      <td>50</td>\n",
       "      <td>63</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     语文  数学  英语  物理  Python\n",
       "张三  100  40  80  42      75\n",
       "王五   90  60  50  63      65"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "****************************************************************************************************\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>物理</th>\n",
       "      <th>Python</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>张三</th>\n",
       "      <td>100</td>\n",
       "      <td>40</td>\n",
       "      <td>80</td>\n",
       "      <td>42</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王五</th>\n",
       "      <td>90</td>\n",
       "      <td>60</td>\n",
       "      <td>50</td>\n",
       "      <td>63</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     语文  数学  英语  物理  Python\n",
       "张三  100  40  80  42      75\n",
       "王五   90  60  50  63      65"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "arr = np.array([\n",
    "    [100,40,80,42,75],\n",
    "    [80,90,90,52,43],\n",
    "    [90,60,50,63,65]\n",
    "])\n",
    "df = pd.DataFrame(arr,index=['张三','李四','王五'],columns=['语文','数学','英语','物理','Python'])\n",
    "display(df)\n",
    "#返回一个标量\n",
    "print(df.iloc[0,2])\n",
    "#返回一行\n",
    "print(df.iloc[2,:],df.iloc[2,:].shape)\n",
    "print('*'*100)\n",
    "#返回一列\n",
    "print(df.iloc[:,2],df.iloc[:,2].shape)\n",
    "#返回一列强制转换为二维\n",
    "print(df.iloc[:,[2]],df.iloc[:,[2]].shape)\n",
    "print('*'*100)\n",
    "display(df.iloc[[0,2,2],[2,0]])\n",
    "display(df.iloc[[True,False,True],:])\n",
    "#取出语文大于80的所有行\n",
    "print(df['语文']>80)\n",
    "#使用iloc取\n",
    "print(df.iloc[:,0]>80)\n",
    "display(df.loc[df.iloc[:,0]>80])\n",
    "#不能使用iloc取\n",
    "# display(df.iloc[df.iloc[:,0]>80])\n",
    "print('*'*100)\n",
    "#如果要使用iloc来取，需要基于numpy来处理\n",
    "display(df.iloc[arr[:,0]>80])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f927642-1986-4d3d-9a54-1c3e8277f5d8",
   "metadata": {},
   "source": [
    "#### loc的使用\n",
    "loc和iloc基本类似，但是可以使用标题的名称来处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "86d1f3e7-f094-413d-97c9-a2c742a61863",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>物理</th>\n",
       "      <th>Python</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>张三</th>\n",
       "      <td>100</td>\n",
       "      <td>40</td>\n",
       "      <td>80</td>\n",
       "      <td>42</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>李四</th>\n",
       "      <td>80</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "      <td>52</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王五</th>\n",
       "      <td>90</td>\n",
       "      <td>60</td>\n",
       "      <td>50</td>\n",
       "      <td>63</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     语文  数学  英语  物理  Python\n",
       "张三  100  40  80  42      75\n",
       "李四   80  90  90  52      43\n",
       "王五   90  60  50  63      65"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42\n",
      "     语文  英语\n",
      "张三  100  80\n",
      "王五   90  50\n",
      "    数学\n",
      "张三  40\n",
      "李四  90\n",
      "王五  60\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "arr = np.array([\n",
    "    [100,40,80,42,75],\n",
    "    [80,90,90,52,43],\n",
    "    [90,60,50,63,65]\n",
    "])\n",
    "df = pd.DataFrame(arr,index=['张三','李四','王五'],columns=['语文','数学','英语','物理','Python'])\n",
    "display(df)\n",
    "print(df.loc['张三','物理'])\n",
    "print(df.loc[['张三','王五'],['语文','英语']])\n",
    "print(df.loc[:,['数学']])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e00ee2ef-824d-43e7-b8c4-2bf7b37756df",
   "metadata": {},
   "source": [
    "### 1.2.4、增删改操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "647523af-3f81-4765-95fb-d37f59588543",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>54</td>\n",
       "      <td>97</td>\n",
       "      <td>189</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96</td>\n",
       "      <td>44</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54</td>\n",
       "      <td>45</td>\n",
       "      <td>163</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "      <td>57</td>\n",
       "      <td>128</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61</td>\n",
       "      <td>31</td>\n",
       "      <td>126</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34</td>\n",
       "      <td>89</td>\n",
       "      <td>166</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95</td>\n",
       "      <td>91</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语   总分  平均分\n",
       "A  38  54  97  189   63\n",
       "B  78  40  82  200   66\n",
       "C  83  96  44  223   74\n",
       "D  64  54  45  163   54\n",
       "E  90  88  46  224   74\n",
       "F  39  32  57  128   42\n",
       "G  34  61  31  126   42\n",
       "H  43  34  89  166   55\n",
       "I  97  37  79  213   71\n",
       "J  77  95  91  263   87"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>54</td>\n",
       "      <td>189</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54</td>\n",
       "      <td>163</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "      <td>128</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61</td>\n",
       "      <td>126</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34</td>\n",
       "      <td>166</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学   总分  平均分\n",
       "A  38  54  189   63\n",
       "B  78  40  200   66\n",
       "C  83  96  223   74\n",
       "D  64  54  163   54\n",
       "E  90  88  224   74\n",
       "F  39  32  128   42\n",
       "G  34  61  126   42\n",
       "H  43  34  166   55\n",
       "I  97  37  213   71\n",
       "J  77  95  263   87"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Chinese</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>54</td>\n",
       "      <td>97</td>\n",
       "      <td>189</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96</td>\n",
       "      <td>44</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54</td>\n",
       "      <td>45</td>\n",
       "      <td>163</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "      <td>57</td>\n",
       "      <td>128</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61</td>\n",
       "      <td>31</td>\n",
       "      <td>126</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34</td>\n",
       "      <td>89</td>\n",
       "      <td>166</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95</td>\n",
       "      <td>91</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Chinese  数学  英语   总分  平均分\n",
       "A       38  54  97  189   63\n",
       "B       78  40  82  200   66\n",
       "C       83  96  44  223   74\n",
       "D       64  54  45  163   54\n",
       "E       90  88  46  224   74\n",
       "F       39  32  57  128   42\n",
       "G       34  61  31  126   42\n",
       "H       43  34  89  166   55\n",
       "I       97  37  79  213   71\n",
       "J       77  95  91  263   87"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "np.random.seed(100)\n",
    "#十人三科的数据\n",
    "arr = np.random.randint(30,100,(10,3))\n",
    "df = pd.DataFrame(arr,index=list('ABCDEFGHIJ'),columns=['语文','数学','英语'])\n",
    "# display(df)\n",
    "#增加一行\n",
    "# df['test'] = 100\n",
    "# display(df)\n",
    "df['总分'] = df[['语文','数学','英语']].sum(axis=1)\n",
    "df['平均分'] = (df['总分']/3).astype(int)\n",
    "display(df)\n",
    "#删除英语一列\n",
    "#inplace=True的话会在原数据中替换\n",
    "df1 = df.drop(columns=['英语'],inplace=False)\n",
    "display(df1)\n",
    "#修改列名\n",
    "df.rename(columns={'语文':'Chinese'},inplace=True)\n",
    "display(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e953084-28bb-4ab7-b759-fb9f76bcb242",
   "metadata": {},
   "source": [
    "### 1.2.5、排序，统计等其他基础操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "30e65d82-810a-4c47-9a63-fa18beca1025",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>54</td>\n",
       "      <td>97</td>\n",
       "      <td>189</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96</td>\n",
       "      <td>44</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54</td>\n",
       "      <td>45</td>\n",
       "      <td>163</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "      <td>57</td>\n",
       "      <td>128</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61</td>\n",
       "      <td>31</td>\n",
       "      <td>126</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34</td>\n",
       "      <td>89</td>\n",
       "      <td>166</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95</td>\n",
       "      <td>91</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语   总分  平均分\n",
       "A  38  54  97  189   63\n",
       "B  78  40  82  200   66\n",
       "C  83  96  44  223   74\n",
       "D  64  54  45  163   54\n",
       "E  90  88  46  224   74\n",
       "F  39  32  57  128   42\n",
       "G  34  61  31  126   42\n",
       "H  43  34  89  166   55\n",
       "I  97  37  79  213   71\n",
       "J  77  95  91  263   87"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96</td>\n",
       "      <td>44</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95</td>\n",
       "      <td>91</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61</td>\n",
       "      <td>31</td>\n",
       "      <td>126</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54</td>\n",
       "      <td>45</td>\n",
       "      <td>163</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>54</td>\n",
       "      <td>97</td>\n",
       "      <td>189</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34</td>\n",
       "      <td>89</td>\n",
       "      <td>166</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "      <td>57</td>\n",
       "      <td>128</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语   总分  平均分\n",
       "C  83  96  44  223   74\n",
       "J  77  95  91  263   87\n",
       "E  90  88  46  224   74\n",
       "G  34  61  31  126   42\n",
       "D  64  54  45  163   54\n",
       "A  38  54  97  189   63\n",
       "B  78  40  82  200   66\n",
       "I  97  37  79  213   71\n",
       "H  43  34  89  166   55\n",
       "F  39  32  57  128   42"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96</td>\n",
       "      <td>44</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95</td>\n",
       "      <td>91</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语   总分  平均分\n",
       "B  78  40  82  200   66\n",
       "C  83  96  44  223   74\n",
       "E  90  88  46  224   74\n",
       "I  97  37  79  213   71\n",
       "J  77  95  91  263   87"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语   总分  平均分\n",
       "B  78  40  82  200   66\n",
       "E  90  88  46  224   74\n",
       "I  97  37  79  213   71"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "语文      64.3\n",
      "数学      59.1\n",
      "英语      66.1\n",
      "总分     189.5\n",
      "平均分     62.8\n",
      "dtype: float64\n",
      "A     88.2\n",
      "B     93.2\n",
      "C    104.0\n",
      "D     76.0\n",
      "E    104.4\n",
      "F     59.6\n",
      "G     58.8\n",
      "H     77.4\n",
      "I     99.4\n",
      "J    122.6\n",
      "dtype: float64\n",
      "语文    97\n",
      "数学    96\n",
      "dtype: int32\n",
      "              语文         数学         英语        总分        平均分\n",
      "count  10.000000  10.000000  10.000000   10.0000  10.000000\n",
      "mean   64.300000  59.100000  66.100000  189.5000  62.800000\n",
      "std    23.879559  25.295806  23.969657   44.0284  14.596803\n",
      "min    34.000000  32.000000  31.000000  126.0000  42.000000\n",
      "25%    40.000000  37.750000  45.250000  163.7500  54.250000\n",
      "50%    70.500000  54.000000  68.000000  194.5000  64.500000\n",
      "75%    81.750000  81.250000  87.250000  220.5000  73.250000\n",
      "max    97.000000  96.000000  97.000000  263.0000  87.000000\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "      <th>班级</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>54</td>\n",
       "      <td>97</td>\n",
       "      <td>189</td>\n",
       "      <td>63</td>\n",
       "      <td>一班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "      <td>一班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96</td>\n",
       "      <td>44</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "      <td>一班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54</td>\n",
       "      <td>45</td>\n",
       "      <td>163</td>\n",
       "      <td>54</td>\n",
       "      <td>二班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "      <td>二班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "      <td>57</td>\n",
       "      <td>128</td>\n",
       "      <td>42</td>\n",
       "      <td>三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61</td>\n",
       "      <td>31</td>\n",
       "      <td>126</td>\n",
       "      <td>42</td>\n",
       "      <td>三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34</td>\n",
       "      <td>89</td>\n",
       "      <td>166</td>\n",
       "      <td>55</td>\n",
       "      <td>四班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "      <td>三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95</td>\n",
       "      <td>91</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "      <td>三班</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文  数学  英语   总分  平均分  班级\n",
       "A  38  54  97  189   63  一班\n",
       "B  78  40  82  200   66  一班\n",
       "C  83  96  44  223   74  一班\n",
       "D  64  54  45  163   54  二班\n",
       "E  90  88  46  224   74  二班\n",
       "F  39  32  57  128   42  三班\n",
       "G  34  61  31  126   42  三班\n",
       "H  43  34  89  166   55  四班\n",
       "I  97  37  79  213   71  三班\n",
       "J  77  95  91  263   87  三班"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "班级\n",
      "一班    204.0\n",
      "三班    182.5\n",
      "二班    193.5\n",
      "四班    166.0\n",
      "Name: 总分, dtype: float64\n",
      "班级\n",
      "一班    63.333333\n",
      "三班    56.250000\n",
      "二班    71.000000\n",
      "四班    34.000000\n",
      "Name: 数学, dtype: float64\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>NaN</td>\n",
       "      <td>97</td>\n",
       "      <td>189</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40.0</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96.0</td>\n",
       "      <td>44</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54.0</td>\n",
       "      <td>45</td>\n",
       "      <td>163</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88.0</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32.0</td>\n",
       "      <td>57</td>\n",
       "      <td>128</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61.0</td>\n",
       "      <td>31</td>\n",
       "      <td>126</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34.0</td>\n",
       "      <td>89</td>\n",
       "      <td>166</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37.0</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95.0</td>\n",
       "      <td>91</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文    数学  英语   总分  平均分\n",
       "A  38   NaN  97  189   63\n",
       "B  78  40.0  82  200   66\n",
       "C  83  96.0  44  223   74\n",
       "D  64  54.0  45  163   54\n",
       "E  90  88.0  46  224   74\n",
       "F  39  32.0  57  128   42\n",
       "G  34  61.0  31  126   42\n",
       "H  43  34.0  89  166   55\n",
       "I  97  37.0  79  213   71\n",
       "J  77  95.0  91  263   87"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>59.666667</td>\n",
       "      <td>97</td>\n",
       "      <td>189</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>78</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>82</td>\n",
       "      <td>200</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>96.000000</td>\n",
       "      <td>44</td>\n",
       "      <td>223</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>54.000000</td>\n",
       "      <td>45</td>\n",
       "      <td>163</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>90</td>\n",
       "      <td>88.000000</td>\n",
       "      <td>46</td>\n",
       "      <td>224</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>57</td>\n",
       "      <td>128</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>34</td>\n",
       "      <td>61.000000</td>\n",
       "      <td>31</td>\n",
       "      <td>126</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>43</td>\n",
       "      <td>34.000000</td>\n",
       "      <td>89</td>\n",
       "      <td>166</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>37.000000</td>\n",
       "      <td>79</td>\n",
       "      <td>213</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>77</td>\n",
       "      <td>95.000000</td>\n",
       "      <td>91</td>\n",
       "      <td>263</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   语文         数学  英语   总分  平均分\n",
       "A  38  59.666667  97  189   63\n",
       "B  78  40.000000  82  200   66\n",
       "C  83  96.000000  44  223   74\n",
       "D  64  54.000000  45  163   54\n",
       "E  90  88.000000  46  224   74\n",
       "F  39  32.000000  57  128   42\n",
       "G  34  61.000000  31  126   42\n",
       "H  43  34.000000  89  166   55\n",
       "I  97  37.000000  79  213   71\n",
       "J  77  95.000000  91  263   87"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "np.random.seed(100)\n",
    "#十人三科的数据\n",
    "arr = np.random.randint(30,100,(10,3))\n",
    "df = pd.DataFrame(arr,index=list('ABCDEFGHIJ'),columns=['语文','数学','英语'])\n",
    "# display(df)\n",
    "#增加一行\n",
    "# df['test'] = 100\n",
    "# display(df)\n",
    "df['总分'] = df[['语文','数学','英语']].sum(axis=1)\n",
    "df['平均分'] = (df['总分']/3).astype(int)\n",
    "display(df)\n",
    "#排序操作\n",
    "display(df.sort_values(by='数学',ascending=False))\n",
    "#筛选操作\n",
    "display(df[df['语文']>70])\n",
    "display(df[(df['语文']>70)&(df['数学']<90)])\n",
    "#统计与聚合\n",
    "print(df.mean())              # 各列均值\n",
    "print(df.mean(axis=1))        # 各行均值\n",
    "print(df[['语文','数学']].max())\n",
    "print(df.describe())          # 描述性统计\n",
    "#添加一个班级信息\n",
    "df['班级'] = ['一班','一班','一班','二班','二班','三班','三班','四班','三班','三班']\n",
    "display(df)\n",
    "#统计数据的平均分\n",
    "print(df.groupby('班级')['总分'].mean())\n",
    "print(df.groupby('班级')['数学'].mean())\n",
    "df.drop(columns=['班级'],inplace=True)\n",
    "#缺失值的处理\n",
    "df.loc['A','数学'] = np.nan\n",
    "display(df)\n",
    "# print(df.isna())\n",
    "display(df.fillna(df.mean()))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62ba8a07-e236-47ac-b1ed-b5ad8505717c",
   "metadata": {},
   "source": [
    "# 二、Pandas实践操作\n",
    "## 2.1、Pandas的文件处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1cd96f56-416d-4e02-b9fe-949e32356d9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>gender</th>\n",
       "      <th>class</th>\n",
       "      <th>age</th>\n",
       "      <th>register_date</th>\n",
       "      <th>city</th>\n",
       "      <th>club</th>\n",
       "      <th>Chinese</th>\n",
       "      <th>Math</th>\n",
       "      <th>English</th>\n",
       "      <th>Physics</th>\n",
       "      <th>Chemistry</th>\n",
       "      <th>Biology</th>\n",
       "      <th>absence_count</th>\n",
       "      <th>height_cm</th>\n",
       "      <th>weight_kg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>23001</td>\n",
       "      <td>褚超琪</td>\n",
       "      <td>M</td>\n",
       "      <td>2B</td>\n",
       "      <td>9</td>\n",
       "      <td>2024-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>合唱</td>\n",
       "      <td>83.2</td>\n",
       "      <td>104.5</td>\n",
       "      <td>999.0</td>\n",
       "      <td>103.4</td>\n",
       "      <td>106.1</td>\n",
       "      <td>77.1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>141.1</td>\n",
       "      <td>43.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23002</td>\n",
       "      <td>孙明丽</td>\n",
       "      <td>男</td>\n",
       "      <td>2B</td>\n",
       "      <td>9</td>\n",
       "      <td>2024-08-25</td>\n",
       "      <td>昆明</td>\n",
       "      <td>篮球</td>\n",
       "      <td>74.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>81.3</td>\n",
       "      <td>67.7</td>\n",
       "      <td>87.8</td>\n",
       "      <td>81.7</td>\n",
       "      <td>4.0</td>\n",
       "      <td>142.5</td>\n",
       "      <td>34.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23003</td>\n",
       "      <td>冯鑫芸</td>\n",
       "      <td>M</td>\n",
       "      <td>2A</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-08-07</td>\n",
       "      <td>昆明</td>\n",
       "      <td>篮球</td>\n",
       "      <td>NaN</td>\n",
       "      <td>58.5</td>\n",
       "      <td>83.9</td>\n",
       "      <td>69.1</td>\n",
       "      <td>57.5</td>\n",
       "      <td>83.4</td>\n",
       "      <td>3.0</td>\n",
       "      <td>140.5</td>\n",
       "      <td>37.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>23004</td>\n",
       "      <td>孔凯霖</td>\n",
       "      <td>女</td>\n",
       "      <td>3B</td>\n",
       "      <td>10</td>\n",
       "      <td>2023-12-15</td>\n",
       "      <td>zhaotong</td>\n",
       "      <td>NaN</td>\n",
       "      <td>76.7</td>\n",
       "      <td>69.7</td>\n",
       "      <td>81.6</td>\n",
       "      <td>77.2</td>\n",
       "      <td>71.1</td>\n",
       "      <td>71.9</td>\n",
       "      <td>4.0</td>\n",
       "      <td>164.0</td>\n",
       "      <td>47.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>23005</td>\n",
       "      <td>杨旭豪</td>\n",
       "      <td>女</td>\n",
       "      <td>4B</td>\n",
       "      <td>11</td>\n",
       "      <td>2024-03-10</td>\n",
       "      <td>zhaotong</td>\n",
       "      <td>足球</td>\n",
       "      <td>67.9</td>\n",
       "      <td>66.8</td>\n",
       "      <td>75.1</td>\n",
       "      <td>65.6</td>\n",
       "      <td>56.6</td>\n",
       "      <td>75.8</td>\n",
       "      <td>2.0</td>\n",
       "      <td>160.2</td>\n",
       "      <td>41.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>23006</td>\n",
       "      <td>何涛</td>\n",
       "      <td>M</td>\n",
       "      <td>3B</td>\n",
       "      <td>11</td>\n",
       "      <td>2024-09-05</td>\n",
       "      <td>NaN</td>\n",
       "      <td>编程</td>\n",
       "      <td>64.8</td>\n",
       "      <td>83.4</td>\n",
       "      <td>66.5</td>\n",
       "      <td>79.1</td>\n",
       "      <td>92.3</td>\n",
       "      <td>81.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>146.4</td>\n",
       "      <td>39.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>23007</td>\n",
       "      <td>吴萌萱</td>\n",
       "      <td>M</td>\n",
       "      <td>2B</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-07-24</td>\n",
       "      <td>曲靖</td>\n",
       "      <td>编程</td>\n",
       "      <td>70.0</td>\n",
       "      <td>79.9</td>\n",
       "      <td>77.2</td>\n",
       "      <td>76.1</td>\n",
       "      <td>81.2</td>\n",
       "      <td>90.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>164.1</td>\n",
       "      <td>26.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>23008</td>\n",
       "      <td>何楠</td>\n",
       "      <td>M</td>\n",
       "      <td>3A</td>\n",
       "      <td>11</td>\n",
       "      <td>2023-11-08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>篮球</td>\n",
       "      <td>75.2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>70.7</td>\n",
       "      <td>84.2</td>\n",
       "      <td>89.7</td>\n",
       "      <td>82.7</td>\n",
       "      <td>2.0</td>\n",
       "      <td>161.1</td>\n",
       "      <td>43.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>23009</td>\n",
       "      <td>赵超豪</td>\n",
       "      <td>M</td>\n",
       "      <td>2B</td>\n",
       "      <td>9</td>\n",
       "      <td>2023-10-13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>足球</td>\n",
       "      <td>63.8</td>\n",
       "      <td>71.9</td>\n",
       "      <td>79.9</td>\n",
       "      <td>62.4</td>\n",
       "      <td>74.3</td>\n",
       "      <td>81.1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>154.6</td>\n",
       "      <td>19.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>23010</td>\n",
       "      <td>华旭琪</td>\n",
       "      <td>女</td>\n",
       "      <td>2B</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-02-26</td>\n",
       "      <td>昭通</td>\n",
       "      <td>NaN</td>\n",
       "      <td>70.8</td>\n",
       "      <td>70.2</td>\n",
       "      <td>79.0</td>\n",
       "      <td>57.9</td>\n",
       "      <td>61.8</td>\n",
       "      <td>79.9</td>\n",
       "      <td>4.0</td>\n",
       "      <td>151.5</td>\n",
       "      <td>39.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   student_id   name gender class  age register_date  ... Physics Chemistry  Biology  absence_count  height_cm  weight_kg\n",
       "0       23001    褚超琪      M    2B    9    2024-09-28  ...   103.4     106.1     77.1            1.0      141.1       43.4\n",
       "1       23002    孙明丽      男    2B    9    2024-08-25  ...    67.7      87.8     81.7            4.0      142.5       34.8\n",
       "2       23003   冯鑫芸       M    2A   10    2024-08-07  ...    69.1      57.5     83.4            3.0      140.5       37.9\n",
       "3       23004    孔凯霖      女    3B   10    2023-12-15  ...    77.2      71.1     71.9            4.0      164.0       47.3\n",
       "4       23005    杨旭豪      女    4B   11    2024-03-10  ...    65.6      56.6     75.8            2.0      160.2       41.1\n",
       "5       23006     何涛      M    3B   11    2024-09-05  ...    79.1      92.3     81.0            2.0      146.4       39.2\n",
       "6       23007    吴萌萱      M    2B   10    2024-07-24  ...    76.1      81.2     90.0            4.0      164.1       26.0\n",
       "7       23008     何楠      M    3A   11    2023-11-08  ...    84.2      89.7     82.7            2.0      161.1       43.4\n",
       "8       23009    赵超豪      M    2B    9    2023-10-13  ...    62.4      74.3     81.1            3.0      154.6       19.1\n",
       "9       23010    华旭琪      女    2B   10    2024-02-26  ...    57.9      61.8     79.9            4.0      151.5       39.4\n",
       "\n",
       "[10 rows x 17 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "****************************************************************************************************\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>gender</th>\n",
       "      <th>class</th>\n",
       "      <th>age</th>\n",
       "      <th>register_date</th>\n",
       "      <th>city</th>\n",
       "      <th>club</th>\n",
       "      <th>Chinese</th>\n",
       "      <th>Math</th>\n",
       "      <th>English</th>\n",
       "      <th>Physics</th>\n",
       "      <th>Chemistry</th>\n",
       "      <th>Biology</th>\n",
       "      <th>absence_count</th>\n",
       "      <th>height_cm</th>\n",
       "      <th>weight_kg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>23112</td>\n",
       "      <td>卫芳桐</td>\n",
       "      <td>M</td>\n",
       "      <td>2A</td>\n",
       "      <td>9</td>\n",
       "      <td>2024-01-03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>编程</td>\n",
       "      <td>86.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>77.8</td>\n",
       "      <td>79.4</td>\n",
       "      <td>89.9</td>\n",
       "      <td>84.3</td>\n",
       "      <td>4.0</td>\n",
       "      <td>152.3</td>\n",
       "      <td>39.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>23113</td>\n",
       "      <td>朱宇</td>\n",
       "      <td>M</td>\n",
       "      <td>3A</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-08-20</td>\n",
       "      <td>zhaotong</td>\n",
       "      <td>合唱</td>\n",
       "      <td>78.7</td>\n",
       "      <td>93.2</td>\n",
       "      <td>73.5</td>\n",
       "      <td>91.6</td>\n",
       "      <td>89.2</td>\n",
       "      <td>93.9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>151.1</td>\n",
       "      <td>41.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>23114</td>\n",
       "      <td>金林涵</td>\n",
       "      <td>男</td>\n",
       "      <td>2A</td>\n",
       "      <td>9</td>\n",
       "      <td>2024-10-07</td>\n",
       "      <td>昆明</td>\n",
       "      <td>编程</td>\n",
       "      <td>73.6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>79.2</td>\n",
       "      <td>61.9</td>\n",
       "      <td>65.5</td>\n",
       "      <td>74.3</td>\n",
       "      <td>2.0</td>\n",
       "      <td>151.4</td>\n",
       "      <td>45.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>23115</td>\n",
       "      <td>张明彤</td>\n",
       "      <td>F</td>\n",
       "      <td>2A</td>\n",
       "      <td>9</td>\n",
       "      <td>2024-10-15</td>\n",
       "      <td>zhaotong</td>\n",
       "      <td>编程</td>\n",
       "      <td>85.8</td>\n",
       "      <td>72.8</td>\n",
       "      <td>93.1</td>\n",
       "      <td>66.8</td>\n",
       "      <td>60.4</td>\n",
       "      <td>85.2</td>\n",
       "      <td>2.0</td>\n",
       "      <td>148.2</td>\n",
       "      <td>33.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>23116</td>\n",
       "      <td>华静杰</td>\n",
       "      <td>M</td>\n",
       "      <td>4B</td>\n",
       "      <td>11</td>\n",
       "      <td>2024-09-26</td>\n",
       "      <td>Kunming</td>\n",
       "      <td>书法</td>\n",
       "      <td>84.9</td>\n",
       "      <td>93.9</td>\n",
       "      <td>91.8</td>\n",
       "      <td>96.7</td>\n",
       "      <td>91.0</td>\n",
       "      <td>77.5</td>\n",
       "      <td>3.0</td>\n",
       "      <td>159.5</td>\n",
       "      <td>40.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>23117</td>\n",
       "      <td>曹瀚霖</td>\n",
       "      <td>男</td>\n",
       "      <td>4B</td>\n",
       "      <td>11</td>\n",
       "      <td>2023-10-24</td>\n",
       "      <td>Kunming</td>\n",
       "      <td>篮球</td>\n",
       "      <td>73.0</td>\n",
       "      <td>96.6</td>\n",
       "      <td>72.4</td>\n",
       "      <td>96.9</td>\n",
       "      <td>85.3</td>\n",
       "      <td>85.4</td>\n",
       "      <td>1.0</td>\n",
       "      <td>162.7</td>\n",
       "      <td>52.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>23118</td>\n",
       "      <td>冯楠玥</td>\n",
       "      <td>男</td>\n",
       "      <td>2A</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-03-30</td>\n",
       "      <td>曲靖</td>\n",
       "      <td>NaN</td>\n",
       "      <td>81.4</td>\n",
       "      <td>85.8</td>\n",
       "      <td>70.6</td>\n",
       "      <td>71.3</td>\n",
       "      <td>72.1</td>\n",
       "      <td>83.2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>158.7</td>\n",
       "      <td>35.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>23119</td>\n",
       "      <td>陶鑫璐</td>\n",
       "      <td>女</td>\n",
       "      <td>3B</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-10-24</td>\n",
       "      <td>Kunming</td>\n",
       "      <td>书法</td>\n",
       "      <td>93.5</td>\n",
       "      <td>95.3</td>\n",
       "      <td>87.8</td>\n",
       "      <td>82.3</td>\n",
       "      <td>91.1</td>\n",
       "      <td>83.9</td>\n",
       "      <td>1.0</td>\n",
       "      <td>158.6</td>\n",
       "      <td>41.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>23120</td>\n",
       "      <td>赵宁睿</td>\n",
       "      <td>M</td>\n",
       "      <td>4A</td>\n",
       "      <td>12</td>\n",
       "      <td>2024-04-09</td>\n",
       "      <td>Kunming</td>\n",
       "      <td>足球</td>\n",
       "      <td>84.7</td>\n",
       "      <td>72.2</td>\n",
       "      <td>76.6</td>\n",
       "      <td>67.8</td>\n",
       "      <td>72.3</td>\n",
       "      <td>81.6</td>\n",
       "      <td>3.0</td>\n",
       "      <td>166.7</td>\n",
       "      <td>39.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>23011</td>\n",
       "      <td>孔雯璐</td>\n",
       "      <td>M</td>\n",
       "      <td>2A</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-09-23</td>\n",
       "      <td>zhaotong</td>\n",
       "      <td>编程</td>\n",
       "      <td>90.0</td>\n",
       "      <td>64.7</td>\n",
       "      <td>67.8</td>\n",
       "      <td>68.4</td>\n",
       "      <td>68.4</td>\n",
       "      <td>92.9</td>\n",
       "      <td>2.0</td>\n",
       "      <td>155.3</td>\n",
       "      <td>32.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name gender class  age register_date  ... Physics Chemistry  Biology  absence_count  height_cm  weight_kg\n",
       "111       23112  卫芳桐      M    2A    9    2024-01-03  ...    79.4      89.9     84.3            4.0      152.3       39.0\n",
       "112       23113   朱宇      M    3A   10    2024-08-20  ...    91.6      89.2     93.9            0.0      151.1       41.8\n",
       "113       23114  金林涵      男    2A    9    2024-10-07  ...    61.9      65.5     74.3            2.0      151.4       45.5\n",
       "114       23115  张明彤      F    2A    9    2024-10-15  ...    66.8      60.4     85.2            2.0      148.2       33.1\n",
       "115       23116  华静杰      M    4B   11    2024-09-26  ...    96.7      91.0     77.5            3.0      159.5       40.5\n",
       "116       23117  曹瀚霖      男    4B   11    2023-10-24  ...    96.9      85.3     85.4            1.0      162.7       52.0\n",
       "117       23118  冯楠玥      男    2A   10    2024-03-30  ...    71.3      72.1     83.2            0.0      158.7       35.0\n",
       "118       23119  陶鑫璐      女    3B   10    2024-10-24  ...    82.3      91.1     83.9            1.0      158.6       41.7\n",
       "119       23120  赵宁睿      M    4A   12    2024-04-09  ...    67.8      72.3     81.6            3.0      166.7       39.1\n",
       "120       23011  孔雯璐      M    2A   10    2024-09-23  ...    68.4      68.4     92.9            2.0      155.3       32.5\n",
       "\n",
       "[10 rows x 17 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "****************************************************************************************************\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>gender</th>\n",
       "      <th>class</th>\n",
       "      <th>age</th>\n",
       "      <th>register_date</th>\n",
       "      <th>city</th>\n",
       "      <th>club</th>\n",
       "      <th>Chinese</th>\n",
       "      <th>Math</th>\n",
       "      <th>English</th>\n",
       "      <th>Physics</th>\n",
       "      <th>Chemistry</th>\n",
       "      <th>Biology</th>\n",
       "      <th>absence_count</th>\n",
       "      <th>height_cm</th>\n",
       "      <th>weight_kg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>23097</td>\n",
       "      <td>李伟坤</td>\n",
       "      <td>F</td>\n",
       "      <td>4A</td>\n",
       "      <td>11</td>\n",
       "      <td>2024-01-06</td>\n",
       "      <td>昆明</td>\n",
       "      <td>篮球</td>\n",
       "      <td>68.2</td>\n",
       "      <td>59.9</td>\n",
       "      <td>72.7</td>\n",
       "      <td>58.4</td>\n",
       "      <td>61.6</td>\n",
       "      <td>74.3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>163.9</td>\n",
       "      <td>49.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>23055</td>\n",
       "      <td>严宇桐</td>\n",
       "      <td>男</td>\n",
       "      <td>3B</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-10-03</td>\n",
       "      <td>昆明</td>\n",
       "      <td>NaN</td>\n",
       "      <td>72.3</td>\n",
       "      <td>77.3</td>\n",
       "      <td>89.8</td>\n",
       "      <td>67.1</td>\n",
       "      <td>73.0</td>\n",
       "      <td>77.7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>150.3</td>\n",
       "      <td>36.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>23060</td>\n",
       "      <td>严颖昕</td>\n",
       "      <td>女</td>\n",
       "      <td>4B</td>\n",
       "      <td>11</td>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>昭通</td>\n",
       "      <td>编程</td>\n",
       "      <td>79.9</td>\n",
       "      <td>NaN</td>\n",
       "      <td>72.8</td>\n",
       "      <td>67.9</td>\n",
       "      <td>78.7</td>\n",
       "      <td>71.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>157.1</td>\n",
       "      <td>44.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>23119</td>\n",
       "      <td>陶鑫璐</td>\n",
       "      <td>女</td>\n",
       "      <td>3B</td>\n",
       "      <td>10</td>\n",
       "      <td>2024-10-24</td>\n",
       "      <td>Kunming</td>\n",
       "      <td>书法</td>\n",
       "      <td>93.5</td>\n",
       "      <td>95.3</td>\n",
       "      <td>87.8</td>\n",
       "      <td>82.3</td>\n",
       "      <td>91.1</td>\n",
       "      <td>83.9</td>\n",
       "      <td>1.0</td>\n",
       "      <td>158.6</td>\n",
       "      <td>41.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>23078</td>\n",
       "      <td>王旭琦</td>\n",
       "      <td>女</td>\n",
       "      <td>4B</td>\n",
       "      <td>12</td>\n",
       "      <td>2024-05-31</td>\n",
       "      <td>Kunming</td>\n",
       "      <td>编程</td>\n",
       "      <td>NaN</td>\n",
       "      <td>76.0</td>\n",
       "      <td>75.9</td>\n",
       "      <td>60.2</td>\n",
       "      <td>69.7</td>\n",
       "      <td>66.6</td>\n",
       "      <td>1.0</td>\n",
       "      <td>164.3</td>\n",
       "      <td>41.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id   name gender class  age  ... Chemistry Biology absence_count  height_cm  weight_kg\n",
       "96        23097   李伟坤       F    4A   11  ...      61.6    74.3           1.0      163.9       49.6\n",
       "54        23055    严宇桐      男    3B   10  ...      73.0    77.7           3.0      150.3       36.1\n",
       "59        23060    严颖昕      女    4B   11  ...      78.7    71.0           1.0      157.1       44.8\n",
       "118       23119    陶鑫璐      女    3B   10  ...      91.1    83.9           1.0      158.6       41.7\n",
       "77        23078    王旭琦      女    4B   12  ...      69.7    66.6           1.0      164.3       41.0\n",
       "\n",
       "[5 rows x 17 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_csv('data/students_raw_utf8.csv', encoding='utf-8',usecols={'student_id','name'})\n",
    "df = pd.read_csv('data/students_raw_utf8.csv',encoding='utf-8')\n",
    "display(df.head(10))#开始的10条\n",
    "print('*'*100)\n",
    "display(df.tail(10))#后面的10条\n",
    "print('*'*100)\n",
    "#随机抽取五条\n",
    "display(df.sample(5,random_state=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "ebd2a519-29bd-4883-9f8f-8e27f3c2ab3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 121 entries, 0 to 120\n",
      "Data columns (total 17 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   student_id     121 non-null    int64  \n",
      " 1   name           121 non-null    object \n",
      " 2   gender         121 non-null    object \n",
      " 3   class          121 non-null    object \n",
      " 4   age            121 non-null    int64  \n",
      " 5   register_date  121 non-null    object \n",
      " 6   city           101 non-null    object \n",
      " 7   club           102 non-null    object \n",
      " 8   Chinese        115 non-null    float64\n",
      " 9   Math           112 non-null    float64\n",
      " 10  English        121 non-null    float64\n",
      " 11  Physics        121 non-null    float64\n",
      " 12  Chemistry      121 non-null    float64\n",
      " 13  Biology        121 non-null    float64\n",
      " 14  absence_count  120 non-null    float64\n",
      " 15  height_cm      121 non-null    float64\n",
      " 16  weight_kg      121 non-null    float64\n",
      "dtypes: float64(9), int64(2), object(6)\n",
      "memory usage: 16.2+ KB\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "None"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>age</th>\n",
       "      <th>Chinese</th>\n",
       "      <th>Math</th>\n",
       "      <th>English</th>\n",
       "      <th>Physics</th>\n",
       "      <th>Chemistry</th>\n",
       "      <th>Biology</th>\n",
       "      <th>absence_count</th>\n",
       "      <th>height_cm</th>\n",
       "      <th>weight_kg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>121.000000</td>\n",
       "      <td>121.000000</td>\n",
       "      <td>115.000000</td>\n",
       "      <td>112.000000</td>\n",
       "      <td>121.000000</td>\n",
       "      <td>121.000000</td>\n",
       "      <td>121.000000</td>\n",
       "      <td>121.000000</td>\n",
       "      <td>120.000000</td>\n",
       "      <td>121.000000</td>\n",
       "      <td>121.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>23060.090909</td>\n",
       "      <td>10.330579</td>\n",
       "      <td>80.170435</td>\n",
       "      <td>80.370536</td>\n",
       "      <td>93.771901</td>\n",
       "      <td>78.548760</td>\n",
       "      <td>77.862810</td>\n",
       "      <td>80.383471</td>\n",
       "      <td>2.008333</td>\n",
       "      <td>154.518182</td>\n",
       "      <td>41.542149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>34.930884</td>\n",
       "      <td>0.934420</td>\n",
       "      <td>8.977525</td>\n",
       "      <td>11.157364</td>\n",
       "      <td>118.098218</td>\n",
       "      <td>12.786876</td>\n",
       "      <td>10.790823</td>\n",
       "      <td>7.509165</td>\n",
       "      <td>1.356564</td>\n",
       "      <td>7.155685</td>\n",
       "      <td>6.052806</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>23001.000000</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>58.800000</td>\n",
       "      <td>54.600000</td>\n",
       "      <td>57.200000</td>\n",
       "      <td>44.500000</td>\n",
       "      <td>52.500000</td>\n",
       "      <td>59.800000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>139.200000</td>\n",
       "      <td>19.100000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>23030.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>74.200000</td>\n",
       "      <td>71.875000</td>\n",
       "      <td>73.000000</td>\n",
       "      <td>68.400000</td>\n",
       "      <td>71.000000</td>\n",
       "      <td>75.500000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>150.100000</td>\n",
       "      <td>38.600000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>23060.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>79.300000</td>\n",
       "      <td>81.900000</td>\n",
       "      <td>78.500000</td>\n",
       "      <td>79.400000</td>\n",
       "      <td>77.600000</td>\n",
       "      <td>80.800000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>154.100000</td>\n",
       "      <td>41.100000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>23090.000000</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>85.500000</td>\n",
       "      <td>88.125000</td>\n",
       "      <td>83.800000</td>\n",
       "      <td>86.300000</td>\n",
       "      <td>85.300000</td>\n",
       "      <td>85.400000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>159.900000</td>\n",
       "      <td>45.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>23120.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>105.000000</td>\n",
       "      <td>105.100000</td>\n",
       "      <td>999.000000</td>\n",
       "      <td>109.500000</td>\n",
       "      <td>106.100000</td>\n",
       "      <td>103.100000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>168.900000</td>\n",
       "      <td>55.600000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         student_id         age     Chinese        Math  ...     Biology  absence_count   height_cm   weight_kg\n",
       "count    121.000000  121.000000  115.000000  112.000000  ...  121.000000     120.000000  121.000000  121.000000\n",
       "mean   23060.090909   10.330579   80.170435   80.370536  ...   80.383471       2.008333  154.518182   41.542149\n",
       "std       34.930884    0.934420    8.977525   11.157364  ...    7.509165       1.356564    7.155685    6.052806\n",
       "min    23001.000000    9.000000   58.800000   54.600000  ...   59.800000       0.000000  139.200000   19.100000\n",
       "25%    23030.000000   10.000000   74.200000   71.875000  ...   75.500000       1.000000  150.100000   38.600000\n",
       "50%    23060.000000   10.000000   79.300000   81.900000  ...   80.800000       2.000000  154.100000   41.100000\n",
       "75%    23090.000000   11.000000   85.500000   88.125000  ...   85.400000       3.000000  159.900000   45.500000\n",
       "max    23120.000000   12.000000  105.000000  105.100000  ...  103.100000       6.000000  168.900000   55.600000\n",
       "\n",
       "[8 rows x 11 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df.shape\n",
    "df.columns\n",
    "#查看基本信息\n",
    "display(df.info())\n",
    "#查看基本的统计信息\n",
    "display(df.describe())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "e39fd347-e1bd-4f2c-bc3d-fd6e71b8540b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>Chinese</th>\n",
       "      <th>Math</th>\n",
       "      <th>English</th>\n",
       "      <th>Physics</th>\n",
       "      <th>Chemistry</th>\n",
       "      <th>Biology</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>23001</td>\n",
       "      <td>褚超琪</td>\n",
       "      <td>83.2</td>\n",
       "      <td>104.5</td>\n",
       "      <td>999.0</td>\n",
       "      <td>103.4</td>\n",
       "      <td>106.1</td>\n",
       "      <td>77.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23002</td>\n",
       "      <td>孙明丽</td>\n",
       "      <td>74.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>81.3</td>\n",
       "      <td>67.7</td>\n",
       "      <td>87.8</td>\n",
       "      <td>81.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23003</td>\n",
       "      <td>冯鑫芸</td>\n",
       "      <td>NaN</td>\n",
       "      <td>58.5</td>\n",
       "      <td>83.9</td>\n",
       "      <td>69.1</td>\n",
       "      <td>57.5</td>\n",
       "      <td>83.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>23004</td>\n",
       "      <td>孔凯霖</td>\n",
       "      <td>76.7</td>\n",
       "      <td>69.7</td>\n",
       "      <td>81.6</td>\n",
       "      <td>77.2</td>\n",
       "      <td>71.1</td>\n",
       "      <td>71.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>23005</td>\n",
       "      <td>杨旭豪</td>\n",
       "      <td>67.9</td>\n",
       "      <td>66.8</td>\n",
       "      <td>75.1</td>\n",
       "      <td>65.6</td>\n",
       "      <td>56.6</td>\n",
       "      <td>75.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>23117</td>\n",
       "      <td>曹瀚霖</td>\n",
       "      <td>73.0</td>\n",
       "      <td>96.6</td>\n",
       "      <td>72.4</td>\n",
       "      <td>96.9</td>\n",
       "      <td>85.3</td>\n",
       "      <td>85.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>23118</td>\n",
       "      <td>冯楠玥</td>\n",
       "      <td>81.4</td>\n",
       "      <td>85.8</td>\n",
       "      <td>70.6</td>\n",
       "      <td>71.3</td>\n",
       "      <td>72.1</td>\n",
       "      <td>83.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>23119</td>\n",
       "      <td>陶鑫璐</td>\n",
       "      <td>93.5</td>\n",
       "      <td>95.3</td>\n",
       "      <td>87.8</td>\n",
       "      <td>82.3</td>\n",
       "      <td>91.1</td>\n",
       "      <td>83.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>23120</td>\n",
       "      <td>赵宁睿</td>\n",
       "      <td>84.7</td>\n",
       "      <td>72.2</td>\n",
       "      <td>76.6</td>\n",
       "      <td>67.8</td>\n",
       "      <td>72.3</td>\n",
       "      <td>81.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>23011</td>\n",
       "      <td>孔雯璐</td>\n",
       "      <td>90.0</td>\n",
       "      <td>64.7</td>\n",
       "      <td>67.8</td>\n",
       "      <td>68.4</td>\n",
       "      <td>68.4</td>\n",
       "      <td>92.9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>121 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id   name  Chinese   Math  English  Physics  Chemistry  Biology\n",
       "0         23001    褚超琪     83.2  104.5    999.0    103.4      106.1     77.1\n",
       "1         23002    孙明丽     74.5    NaN     81.3     67.7       87.8     81.7\n",
       "2         23003   冯鑫芸       NaN   58.5     83.9     69.1       57.5     83.4\n",
       "3         23004    孔凯霖     76.7   69.7     81.6     77.2       71.1     71.9\n",
       "4         23005    杨旭豪     67.9   66.8     75.1     65.6       56.6     75.8\n",
       "..          ...    ...      ...    ...      ...      ...        ...      ...\n",
       "116       23117    曹瀚霖     73.0   96.6     72.4     96.9       85.3     85.4\n",
       "117       23118    冯楠玥     81.4   85.8     70.6     71.3       72.1     83.2\n",
       "118       23119    陶鑫璐     93.5   95.3     87.8     82.3       91.1     83.9\n",
       "119       23120    赵宁睿     84.7   72.2     76.6     67.8       72.3     81.6\n",
       "120       23011    孔雯璐     90.0   64.7     67.8     68.4       68.4     92.9\n",
       "\n",
       "[121 rows x 8 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "score_cols = ['student_id','name','Chinese','Math','English','Physics','Chemistry','Biology']\n",
    "df1 = df[score_cols]\n",
    "display(df1)\n",
    "df.to_csv('data/student_score.csv',index=False,encoding='utf-8-sig')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09d21eee-83a1-4a5e-b709-cb1f8c2f7769",
   "metadata": {},
   "source": [
    "## 2.2.文件的合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f83abc6-66db-4ef8-ab69-e3296fca1a54",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
